﻿using System.Transactions;
using Natural.Attributes;
using Natural.Model;
using Natural.Providers;

namespace Natural.Decorators
{
    [Impl(Type = ImplType.Decorator, Name = "Invoker", Strategy = "Transaction", Version = 0, Priority = 0)]
    public class InvokerTransactionDecorator : IInvoker
    {
        private IInvoker Decorated;
        public InvokerTransactionDecorator(IInvoker decorated)
        {
            Decorated = decorated;
        }
        public void Invoke(InvokeContext context)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
               Decorated.Invoke(context);
               transaction.Complete(); 
            }
        }
    }
}
